import pandas as pd
import numpy as np

# 抽样
# -- 使用.take（）函数排序
# -- 可以借助np.random.permutation()函数随机顺序

data = np.random.randint(0, 10, size=(4,4))
df = pd.DataFrame(data,index=list('ABCD'),columns=['python','java','c++','php'])
print(df)
# 1.无放回抽样
print('\n1.无放回抽样：')
df1 = df.copy()

print(df1.take([3, 0, 1, 2]))  # 行排序
print(df1.take([2, 3, 0, 1],axis=1)) # 列排序

print(np.random.permutation([0, 1, 2, 3]))  # 随机排列

print('无放回抽样：依次随机取出，没有重复值')
print(df1.take(np.random.permutation([0, 1, 2, 3])))



# 2.有放回抽样:有可能出现重复值
print('\n2.有放回抽样：')
df2 = df.copy()
print(df2)
print(np.random.randint(0, 4, size=6))  # 随机选择4个索引

print(df2.take(np.random.randint(0, 4, size=6)))




